package euler.p001_050;

import euler.MainEuler;

public class Euler019 extends MainEuler {

    /*
        You are given the following information,
        but you may prefer to do some research for yourself.

            1 Jan 1900 was a Monday.

            Thirty days has September,
            April, June and November.
            All the rest have thirty-one,
            Saving February alone,
            Which has twenty-eight, rain or shine.
            And on leap years, twenty-nine.

        A leap year occurs on any year evenly divisible by 4,
        but not on a century unless it is divisible by 400.

        How many Sundays fell on the first of the month during
        the twentieth century (1 Jan 1901 to 31 Dec 2000)?

     */
    public String resolve() {

        int year = 1900;
        int currentDate = 1;
        int suma = 0;

        currentDate+=31;
        currentDate+=28;
        currentDate+=31;
        currentDate+=30;
        currentDate+=31;
        currentDate+=30;
        currentDate+=31;
        currentDate+=31;
        currentDate+=30;
        currentDate+=31;
        currentDate+=30;
        currentDate+=31;
        year++;

        while (year < 2001) {
            if (currentDate % 7 == 0) {
                suma++;
            }
            currentDate+=31;

            if (currentDate % 7 == 0) {
                suma++;
            }
            if (year % 4 == 0) {
                currentDate+=29;
            } else {
                currentDate+=28;
            }

            if (currentDate % 7 == 0) {
                suma++;
            }
            currentDate+=31;

            if (currentDate % 7 == 0) {
                suma++;
            }
            currentDate+=30;

            if (currentDate % 7 == 0) {
                suma++;
            }
            currentDate+=31;

            if (currentDate % 7 == 0) {
                suma++;
            }
            currentDate+=30;

            if (currentDate % 7 == 0) {
                suma++;
            }
            currentDate+=31;

            if (currentDate % 7 == 0) {
                suma++;
            }
            currentDate+=31;

            if (currentDate % 7 == 0) {
                suma++;
            }
            currentDate+=30;

            if (currentDate % 7 == 0) {
                suma++;
            }
            currentDate+=31;

            if (currentDate % 7 == 0) {
                suma++;
            }
            currentDate+=30;

            if (currentDate % 7 == 0) {
                suma++;
            }
            currentDate+=31;

            year++;
        }

        return String.valueOf(suma);
    }
}
